# ----------------------------------------------
# Configuration variables taken from ./configure
# ----------------------------------------------
CPPFLAGS     = @CPPFLAGS@
CXX          = @CXX@
CXXFLAGS     = @CXXFLAGS@
DEFINES      = @DEFS@
LDFLAGS      = @LDFLAGS@
EXTRA_LIBS         = @LIBS@
prefix       = @prefix@
PLATFORM    ?= @build@
DYNINST_VER  = @DYNINST_VER@

INSTALL      = @INSTALL@

vpath % @srcdir@/src

# -------------------------------------------
# Begin Makefile based on variables set above
# -------------------------------------------
.PHONY: clean ready

SRCS         = dyner.C

OBJS         = $(SRCS:%.C=%.o)

CXXFLAGS    += -Wall
LIBS        += -ldynC_API -ldyninstAPI -lstackwalk -lpcontrol -lpatchAPI -lparseAPI -linstructionAPI -lsymtabAPI -lsymLite -ldynDwarf -ldynElf -lcommon -pthread -lelf -ldwarf -liberty

ifeq (freebsd, $(findstring freebsd, $(PLATFORM)))
LIBS	    += -lpthread
endif

ifeq (ppc64_linux, $(findstring ppc64_linux, $(PLATFORM)))
CXXFLAGS	+= -m64
CFLAGS		+= -m64
endif

LIBS += ${EXTRA_LIBS}

all: ready dyner

install: dyner
	@if [ $(prefix) != "." ]; then                           \
		echo "$(INSTALL) -d $(prefix)";                  \
		$(INSTALL) -d $(prefix);                         \
		echo "$(INSTALL) dyner $(prefix)/bin/dyner"; \
		$(INSTALL) dyner $(prefix)/bin/dyner;        \
	fi


dyner: $(OBJS)
	$(CXX) $(CXXFLAGS) $^ -o $@ $(LDFLAGS) $(LIBS)

clean:
	rm -f dyner *.o *.so

distclean: clean
	rm Makefile config.log config.status

ready:
	@echo "Begin dyner build for $(PLATFORM)"

$(OBJS): %.o: %.C
	$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(DEFINES) $^ -c -o $@

alarm: alarm.c liblib.so
	gcc -Wall -g -o alarm alarm.c liblib.so

liblib.so: lib.c
	gcc -Wall -g -shared -o liblib.so lib.c
